package org.gcb.core.ui.nodes;

import java.beans.IntrospectionException;
import java.util.List;
import org.gcb.core.model.Toon;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.BeanNode;
import org.openide.nodes.ChildFactory;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.util.lookup.Lookups;

public class SampleChildFactory extends ChildFactory<Toon>{
    private List<Toon> resultList;

    public SampleChildFactory(List<Toon> resultList) {
        this.resultList = resultList;
    }

    @Override
    protected boolean createKeys(List<Toon> toPopulate) {
        for (Toon toon : resultList) {
            toPopulate.add(toon);
        }
        return true;
    }

    @Override
    protected Node createNodeForKey(Toon key) {
        Node node;
        try {
            node = new BeanNode(key);
        } catch (IntrospectionException ex) {
        }
            node = new AbstractNode(Children.LEAF, Lookups.singleton(key));
        node.setDisplayName(key.getName());
        return node;
//        try {
//            BeanNode<Toon> n = new BeanNode<Toon>(key);
//            n.setName(key.getName());
//            return n;
//        } catch (IntrospectionException e) {
//            Exceptions.printStackTrace(e);
//            return null;
//        }
    }

}
